<script>
	export default {
		globalData: {
			userInfo: {},
			dayAnswerRes: null,
			goodsInfo: {},
			addressInfo: {},
			uid: '',
			zxAnswerRes: {}
		},
		onLaunch: function(options) {
			uni.getStorageSync('addressInfo')
			uni.getStorageSync('goodsInfo')
			uni.getStorageSync('userInfo')

			console.log('App Launch', options)

			 var sceneParams = this.parseSceneToObject(options.query?.scene ?? '');
			console.log(sceneParams)
			this.globalData.uid = sceneParams.uid || ''
			console.log(this.globalData)
		},
		onShow: function() {
			console.log('进入小程序');
			const sysPortalUserIn = async () => {
				try {
					const res = await this.$http.post(
					'/yaolexue-service-portal/sysPortalUser/sysPortalUserIn');
					console.log('进入小程序', res);


				} catch (error) {

					console.error('Error in sysPortalUserIn request:', error);
				}
			};

			sysPortalUserIn();

		},
		onHide: function() {
			console.log('离开小程序');
			const sysPortalUserOut = async () => {
				try {
					const res = await this.$http.post(
						'/yaolexue-service-portal/sysPortalUser/sysPortalUserOut');
					console.log('离开小程序', res);
					if (res.code !== 200) {
						uni.showToast({
							title: '离开失败!',
							icon: 'error'
						})
					}

				} catch (error) {

					console.error('Error in sysPortalUserIn request:', error);
				}
			};

			sysPortalUserOut();
		},
		methods:{
			parseSceneToObject(scene) {
			  if (!scene) {
			    return {};
			  }
			
			  // 先进行URL解码
			  var sceneStr = decodeURIComponent(scene);
			
			  // 分割成多个参数对
			  var paramsArray = sceneStr.split('&');
			
			  var paramsObj = {};
			  for (var pair of paramsArray) {
			    var parts = pair.split('=');
			    if (parts.length === 2) {
			      paramsObj[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]);
			    }
			  }
			
			  return paramsObj;
			}
		}
	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "@/uni_modules/uview-ui/index.scss";
	@import "@/common/styles/common.scss";
	@import "@/common/styles/index.scss";
	@import "/wxcomponents/vant/dist/common/index.wxss";
</style>